package es.ats.codington.web.servlets;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import es.ats.codington.festival.domain.Event;
import es.ats.codington.festival.services.EventServiceImpl;
import es.ats.codington.festival.services.EventSingUpService;

/**
 * Servlet implementation class ListAllEventServlet.
 */
@WebServlet("/ListAllEventServlet")
public class ListAllEventServlet extends HttpServlet {
	
	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;
       
    /**
     * Instantiates a new list all event servlet.
     *
     * @see HttpServlet#HttpServlet()
     */
    public ListAllEventServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * Do get.
	 *
	 * @param request the request
	 * @param response the response
	 * @throws ServletException the servlet exception
	 * @throws IOException Signals that an I/O exception has occurred.
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession(true);
	   	 int idV =(Integer) session.getAttribute("VisitorID");

			System.out.println(idV);
			try{		
				EventServiceImpl eve = new EventServiceImpl();
				ArrayList<Event> event = new ArrayList<Event>();
				
				event = eve.obtainAllEvent();

				session.setAttribute("AllEvents", event);

				RequestDispatcher rd=request.getRequestDispatcher("listEventAdmin.jsp");  
	            rd.include(request,response); 
				
		
	    }catch(Exception theException){
	        System.out.println(theException); 
	   }
	}

	/**
	 * Do post.
	 *
	 * @param request the request
	 * @param response the response
	 * @throws ServletException the servlet exception
	 * @throws IOException Signals that an I/O exception has occurred.
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		


	}
	
	/**
	 * Send list all event.
	 *
	 * @param request the request
	 * @param response the response
	 */
	public void sendListAllEvent(HttpServletRequest request, HttpServletResponse response){
	   	 HttpSession session = request.getSession(true);
	   	 int idV =(Integer) session.getAttribute("VisitorID");

			System.out.println(idV);
			try{		
				EventServiceImpl eve = new EventServiceImpl();
				ArrayList<Event> event = new ArrayList<Event>();
				
				event = eve.obtainAllEvent();

				session.setAttribute("AllEvents", event);

				RequestDispatcher rd=request.getRequestDispatcher("listEventAdmin.jsp");  
	            rd.include(request,response); 
				
		
	    }catch(Exception theException){
	        System.out.println(theException); 
	   }
			
}

}
